<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="岗位名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入岗位名称" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="公司名称" prop="configKey">
        <el-input v-model="queryParams.configKey" placeholder="请输入公司名称" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="configList">
      <el-table-column label="" width="1000rpx" align="center">
        <template slot-scope="props">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>岗位名称：{{ props.row.name }}</span>
              <el-button style="float: right; padding: 3px 0" type="text"></el-button>
            </div>
            <div class="text item">
              岗位介绍：{{ props.row.introduction }}
            </div>
            <div class="text item">
              薪资范围：{{ props.row.minSalary + "---" + props.row.maxSalary }}
            </div>
            <div class="text item">
              联系人：{{ props.row.createBy }}
            </div>
            <div class="text item">
              公司名称：{{ props.row.enterpriseName }}
            </div>
            <div class="text item" v-if="!isEnterprise">
              <el-button type="primary" @click="jumpToUserContent(props.row)" round>岗位咨询</el-button>
            </div>
          </el-card>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>

    </el-dialog>
  </div>
</template>

<script>
import { getConfig, delConfig, addConfig, updateConfig, refreshCache } from "@/api/system/config";
import { listPosition } from "@/api/system/position";
import { jumpToContent } from "@/api/system/dialogue";
export default {
  name: "Config",
  dicts: ['sys_yes_no'],
  data() {
    return {
      isEnterprise: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 参数表格数据
      configList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        configName: undefined,
        configKey: undefined,
        configType: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        configName: [
          { required: true, message: "参数名称不能为空", trigger: "blur" }
        ],
        configKey: [
          { required: true, message: "参数键名不能为空", trigger: "blur" }
        ],
        configValue: [
          { required: true, message: "参数键值不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    jumpToUserContent(positionInfo) {
      var info = {
        positionId: positionInfo.id,
        enterprise: null
      }
      this.configList.forEach(element => {
        if (element.id == info.positionId) {
          info.enterprise = element.enterprise
        }
      });
      jumpToContent(info).then(res => {
        localStorage.setItem("jump", true)
        localStorage.setItem("jumpList", res.rows)
        this.$router.push({
          path: 'enterpriseUserCommunication',

        })
      })
    },
    /** 查询参数列表 */
    getList() {
      this.loading = true;
      listPosition(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.configList = response.rows;
        console.log(JSON.stringify(this.configList))
        this.total = response.total;
        this.loading = false;
        var roleList = localStorage.getItem("roles")
        if(roleList == "enterpriseRole") {
            this.isEnterprise = true 
          }

      }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        configId: undefined,
        configName: undefined,
        configKey: undefined,
        configValue: undefined,
        configType: "Y",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加参数";
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const configId = row.configId || this.ids
      getConfig(configId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改参数";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.configId != undefined) {
            updateConfig(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addConfig(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const configIds = row.configId || this.ids;
      this.$modal.confirm('是否确认删除参数编号为"' + configIds + '"的数据项？').then(function () {
        return delConfig(configIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/config/export', {
        ...this.queryParams
      }, `config_${new Date().getTime()}.xlsx`)
    },
    /** 刷新缓存按钮操作 */
    handleRefreshCache() {
      refreshCache().then(() => {
        this.$modal.msgSuccess("刷新成功");
      });
    }
  }
};

</script>
<style>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.box-card {
  width: 100%;
}
</style>